#define _CRT_SECURE_NO_WARNINGS 1
#include"heap.h"

void HeapSort(int* a, int n)
{
	assert(a);
	for (int i = (n - 1) / 2; i > 0; i--)
	{
		AdjustDown(a, n, i);
	}
	int k = n - 1;
	while (k > 0)
	{
		Swap(&a[0], &a[k]);
		AdjustDown(a, k, 0);
		k--;
	}
}

int main()
{
	int a[10] = { 10,9,8,7,6,5,4,3,2,1 };
	for (int i = 0; i < 10; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
	HeapSort(a, 10);
	for (int i = 0; i < 10; i++)
	{
		printf("%d ", a[i]);
	}

	return 0;
}